
Ext.onReady(function() {

	var store = Ext.create('Ext.data.Store', {
		pageSize : 50,
		fields : [ "ID", "BATCHNO", "SENDER", "RECIVER", "SENDDATE", "MESSAGE" ]
	});

	var grid = Ext.create('Ext.grid.Panel', {
		title : str_import_curimp,
		region : 'center',
		border: false,
		split : true,
		store : store,
		loadMask : true,
		multiSelect : true,
		columns : [ {
			xtype : 'rownumberer',
			width : 40,
			sortable : false
		}, {
			text : "ID",
			dataIndex : 'ID',
			width : 80,
			hidden : true
		}, {
			text : "BATCHNO",
			dataIndex : 'BATCHNO',
			width : 80,
			hidden : true
		}, {
			text : str_import_sendno,
			dataIndex : 'SENDER',
			width : 120
		}, {
			text : str_import_recvno,
			dataIndex : 'RECIVER',
			width : 120
		}, {
			text : str_import_senddate,
			dataIndex : 'SENDDATE',
			width : 150
		}, {
			text : str_import_msgcontent,
			autoScroll : true,
			dataIndex : 'MESSAGE',
			flex : 1
		},{
            xtype: 'actioncolumn',
            width: 25,
            items: [{
                icon   : ctx + '/common/images/delete.png',
                tooltip: 'delete',
                handler: function(grid, rowIndex, colIndex) {
                    var id = store.getAt(rowIndex).get('ID');
                    Ext.Ajax.request({
        				url : ctx + '/ab/po/message.do',
        				params : {
        					md : 'dMessage',
        					ID : [id]
        				},
        				success: function(response){
        					store.load();
        			    }
        			});
                }
            }]
        }],
		bbar : Ext.create('Ext.PagingToolbar', {
			store : store,
			displayInfo : true
		})
	});
	
	var msgLabel = Ext.create('Ext.form.Label', {
		text : ""
	});

	var gridForm = Ext.create('Ext.form.Panel', {
        layout: 'border',
        border: false,
        region:'east',
        width: 300,
		items : [{
			margin : '0 0 0 10',
			xtype : 'fieldset',
			title : str_import_msgimp,
			defaults : {
				width : 240
			},
			items : [ {
				labelWidth : 50,
				xtype : 'filefield',
				buttonText : str_import_sel,
				fieldLabel : str_import_file,
				name : 'file',
				allowBlank : false
			}, msgLabel]
		}, {
			xtype : 'hidden',
			name : 'md',
			value : 'importMsg'
		}],
		buttons : [{
			text : str_import_imp,
			handler : function() {
				if (gridForm.getForm().isValid()) {
					gridForm.getForm().submit({
						url : ctx + '/ab/po/message.do',
						waitMsg: str_import_waiting,
						success : function(form, action) {
							var batchNo = action.result.msg;
							store.setProxy({
								type : 'ajax',
								url : ctx + '/ab/po/message.do?md=qMessage&batchNo=' + batchNo,
								reader : {
									type : 'json',
									root : 'message',
									totalProperty : 'totalCount'
								}
							});
							store.loadPage(1);
						},
						failure : function(form, action) {
							msgLabel.setText(action.result.msg);
						}
					});
				}
			}
		}]
	});
	
	var view = Ext.create('Ext.container.Viewport', {
		layout : 'border',
		items : [ grid , gridForm],
		renderTo : Ext.getBody()
	});

});